package com.demo.controller;

import com.demo.dao.UserRepository;
import com.demo.pojo.User;
import com.demo.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/16 9:59
 * @Version 1.0
 **/
@RequestMapping("user")
@Controller
public class UserController {
    @Autowired
    UserService service;

    @RequestMapping("unPermission")
    public String unPermission() {
        return "unauth";
    }

    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("loginOut")
    public String loginOut() {
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "redirect:/user/toLogin";
    }

    @RequestMapping("login")
    public String login(User user) {
        boolean b = service.login(user);
        System.out.println(b);
        if (b){
            return "index";
        }
        return "redirect:login";
    }

    @RequestMapping("findAll")
    @RequiresPermissions(value = {"findAll"})
    public String findAll(){
        return "studentlist";
    }

    @RequiresPermissions(value ={"insert"})
    @RequestMapping("/insert")
    public String insert(){
        return "insert";
    }
    @RequiresPermissions(value ={"update"})
    @RequestMapping("/update")
    public String update(){
        return "update";
    }
    @RequiresPermissions(value ={"delete"})
    @RequestMapping("/delete")
    public String delete(){
        return "delete";
    }
}
